import { program } from 'commander';
import { CommandLoader } from './commands';

export function bootstrap(): void {
  program
    .version(
      require('../../package.json').version,
      '-V, --version',
      'output the version number',
    )
    .usage('<command> [options]')
    .helpOption('-h, --help', 'output usage information')
    .configureOutput({
      writeErr: str => process.stdout.write(`[ERR] ${str}`),
      outputError: (str, write) => write(`\x1b[31m${str}\x1b[0m`),
    });
  CommandLoader.load(program);
  program.parse(process.argv);
  if (!process.argv.slice(2).length) {
    program.outputHelp();
  }
}